package com.eqdd.yiqidian.ui.base;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.view.View;
import android.view.WindowManager;

import com.eqdd.inputs.AndroidNextInputs;
import com.eqdd.inputs.WidgetAccess;
import com.eqdd.nextinputs.Scheme;
import com.eqdd.nextinputs.StaticScheme;
import com.eqdd.yiqidian.EditTextActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.BaseActivity;
import com.eqdd.yiqidian.base.Config;


public class EditTextActivity extends BaseActivity {
    private EditTextActivityCustom dataBinding;
    private String tip;
    private String title;
    private String content;
    private AndroidNextInputs inputs;
    private WidgetAccess access;

    @Override
    public void initBinding() {
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_edit_text);
        title = getIntent().getStringExtra("title");
        tip = getIntent().getStringExtra("tip");
        content = getIntent().getStringExtra("content");
        boolean canBlank = getIntent().getBooleanExtra("canBlank", false);
        dataBinding.etContent.setText(content);
        dataBinding.tvTip.setText(tip);
        inputs = new AndroidNextInputs();
        access = new WidgetAccess(this);
        if (AppConstent.schemes != null && AppConstent.schemes.size() > 0) {
            if (!canBlank) {
                AppConstent.schemes.add(StaticScheme.Required());
            }
            Scheme[] schemes = new Scheme[AppConstent.schemes.size()];
            AppConstent.schemes.toArray(schemes);
            inputs.add(access.findEditText(R.id.et_content), schemes);
        } else {
            if (!canBlank) {
                inputs.add(access.findEditText(R.id.et_content), StaticScheme.Required());
            }
        }
        initTopTitleBar(View.VISIBLE, title);
        initTopRightText("完成", (v) -> {
            if (inputs.test()) {
                Intent intent = new Intent();
                intent.putExtra("content", dataBinding.etContent.getText().toString());
                setResult(Config.INTENT_CONTENT, intent);
                finish();
            }
        });
    }

    @Override
    public void initData() {
    }

    @Override
    public void setView() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }
}
